import React from 'react';
import { inject, observer } from 'mobx-react';
import { Spin, Button, Icon, message, Tooltip, Modal, Popover,Slider,Row, Col } from 'antd'
import { WeaPopoverHrm, WeaTab, WeaDropdown, WeaTop,WeaDialog, WeaLocaleProvider, WeaNewScroll, WeaTools, WeaCheckbox,WeaTextarea,WeaInput, WeaProgress, WeaTag,WeaRightMenu } from 'ecCom';
import { routerShape } from 'react-router';
import BaseInfo from './taskdetail/BaseInfo';
import SubTask from './taskdetail/SubTask';
import RelateInfo from './taskdetail/RelateInfo';
import FeedInfo from './taskdetail/FeedInfo';
import LogInfo from './taskdetail/LogInfo';
import TagChoiceBox from '../../public/tag/TagChoiceBox'
import * as Util from '../../util/Util';
import dict from '../../util/wea-workrelate-file';
import ReactDOM from 'react-dom';
dict.addWindowFunc();
const toJS = mobx.toJS;
const getLabel = WeaLocaleProvider.getLabel;
const formatMultiLang = WeaLocaleProvider.formatMultiLang
const { ButtonSelect } = WeaDropdown;
@inject('taskDetailStore')
@observer
export default class TaskDetail extends React.Component {
    static contextTypes = {
        router: routerShape
    }
    constructor(props) {
        super(props);
        this.state = {
            viewHeight: this.getHeight(),
            showKey: '',
            topTab: [
                {
                    title: getLabel(1361, '基本信息'),
                    viewcondition: 1
                },
                {
                    title: getLabel(83802, '下级任务'),
                    viewcondition: 2
                },
                {
                    title: getLabel(22078, '相关信息'),
                    viewcondition: 3
                },
                {
                    title: getLabel(83596, '反馈信息'),
                    viewcondition: 4,
                    showcount: true,
                    groupid: "newfbcount",
                    color:"#ff3232",
                },
                {
                    title: getLabel(32061, '操作日志'),
                    viewcondition: 5
                }
            ],
            dropData: [{ key: '1', show: getLabel(32136, '批量删除') },
            { key: '2', show: getLabel(390705, '批量标记') }],
            refusevisable:false,
            refuseval:"",
            collectParams :{},
            currentbtn:1,
            dialogtitle:"",
            remindval:getLabel(517828, '请抓紧处理此任务'),
            pcheckval:1,
            ccheckval:0
        }
    }
    componentWillMount() {//一些初始化请求
        this.getFileCategory();
        this.renderDetail();
    }
    componentWillReceiveProps(newProps) {
        if (newProps.detailKey != this.props.detailKey || newProps.refeshid != this.props.refeshid) {
            this.getFileCategory();
            const { taskDetailStore } = newProps;
            taskDetailStore.tabselectKey = 1;
            taskDetailStore.detailKey = newProps.detailKey;
            taskDetailStore.initForm({ taskId: newProps.detailKey });
            this.setCollection(newProps.detailKey);
            taskDetailStore.isFb = newProps.isFb;
            if (taskDetailStore.isFb) {
                taskDetailStore.tabselectKey = 4;
            }
        }
    }
    componentDidUpdate() {
        const { taskDetailStore } = this.props;
        if (taskDetailStore.scrollstatus == 1) {
            if (this.refs.taskNewScroll) {
                this.refs.taskNewScroll.scrollerToTop();
            }
            taskDetailStore.scrollstatus = 0;
        }
        if (taskDetailStore.checknew == 1 && typeof this.props.onCheckNew === "function") {
            taskDetailStore.checknew = 0;
            this.props.onCheckNew();
        }
        if(location.href.indexOf("/main/workrelate/task/taskDetail")>-1){
            document.title=taskDetailStore.editParams.name;
        }
    }
    renderDetail() {
        const { taskDetailStore, isFb, detailKey } = this.props;
        let dKey = detailKey;
        if (!dKey) {
            dKey = Util.getParams("id");
        }
        taskDetailStore.tabselectKey = 1;
        taskDetailStore.detailKey = dKey;
        taskDetailStore.initForm({ taskId: dKey });
        this.setCollection(dKey);
        taskDetailStore.isFb = isFb;
        if (taskDetailStore.isFb) {
            taskDetailStore.tabselectKey = 4;
        }
    }
    //设置收藏名称
    setCollection = (key) =>{
        let collectParams = {
            favname: getLabel(508789, '任务详情'),
            favouritetype: 5,
            link: '/spa/workrelate/static/index.html#/main/workrelate/task/taskDetail?id='+key,
            importantlevel: 1,
        }
        this.setState({collectParams:collectParams})
    }
    getFileCategory() {
        WeaTools.callApi('/api/workrelate/task/getTaskFileCategory', 'GET', {}).then((data) => {
            if (data.status == 1) {
                const { taskDetailStore } = this.props;
                taskDetailStore.category = data.secId;
                taskDetailStore.maxUploadSize = data.maxsize;
            }
        });
    }
    getHeight() {
        let { minusHeight, _height } = this.props;
        if (minusHeight == undefined) {
            minusHeight = 0;
        }
        let _h = window.innerHeight - 130 - minusHeight;
        if (_height && _height < _h) {
            _h = _height;
        }
        return _h;
    }
    resetUrlKey() {
        //弹框更改url上的_key值
        const { pathname, search,taskDetailStore } = this.props;
        let url = `/${pathname}${search}`;
        if (pathname == undefined || search == undefined) {
            if(location.href.indexOf("/main/workrelate/task/taskDetail")>-1){
                url = "/main/workrelate/task/taskDetail?id="+taskDetailStore.detailKey;
            } else if (location.href.indexOf("/main/workrelate/task/taskMain")>-1) {
                url = "/main/workrelate/task/taskMain";
            } else{
                url = "/main/workrelate/task/taskIndex";
            }
        }
        this.context.router.push({
            pathname: url
        });
    }
    getButtons(_btype) {
        const { taskDetailStore } = this.props;
        if (!taskDetailStore.hasData) {
            return;
        }
        let arry = [];
        let rightarry = [];
        const {isconfirm,candel,canShow,editParams,canremind,canaudit,auditperson} = taskDetailStore;
        if(isconfirm){
            arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@4fld6v@receive`} title={getLabel(18526,'接收')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@4jfymx@receive`} onClick={()=>this.toChangeStatus("status",100,getLabel(515080,'确认要接收此任务吗？'))}>{getLabel(18526,'接收')}</Button></Tooltip>);
            arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@6tru9i@refuse`} title={getLabel(25659,'拒绝')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@3tb04e@refuse`} onClick={()=>this.refuseDialog(true,1,getLabel(516927, '请填写拒绝理由'))}>{getLabel(25659,'拒绝')}</Button></Tooltip>);
            rightarry.push({key: '0',icon: <i className='icon-coms-down-001' />,content: getLabel(18526,'接收'),onClick: key => this.toChangeStatus("status",100,getLabel(515080,'确认要接收此任务吗？'))});
            rightarry.push({key: '1',icon: <i className='icon-coms-Return' />,content: getLabel(25659,'拒绝'),onClick: key => this.refuseDialog(true,1,getLabel(516927, '请填写拒绝理由'))});
            if(_btype==1){
                return rightarry;
            }else{
                return arry;
            }
        }
        let name = getLabel(503684, '取消关注');
        let i_type = "icon-coms-Collection2";
        if (editParams.special == 0){
            i_type = "icon-coms-Collection";
            name = getLabel(504445, '关注');
        } 
        arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@oek0v5@collection`} title={name}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@w0lfg0@collection`} onClick={() => this.toChangeStatus('collection')}>{name}</Button></Tooltip>);
        rightarry.push({key: '3',icon: <i className={i_type}/>,content: name,onClick: key => this.toChangeStatus('collection')});
        if (canShow && !canaudit) {
            let title = getLabel(382573, '设置为进行中');
            let _type = "status";
            i_type = "";
            if (editParams.status == 1) {
                name = getLabel(555, '完成');
                title = getLabel(382574, '设置为完成');
                i_type = "icon-coms-complete";
            }else if(editParams.status == 4){
                name = getLabel(515068, '待确认');
                title = getLabel(515071, '待责任人确认是否接受此任务');
                _type = "";
            }else if(editParams.status == 5){
                name = getLabel(514155,'重发');
                title = getLabel(515078,'责任人已拒绝,重新向责任人发送任务');
                _type = "resend";
                i_type= "icon-coms-lower";
            }else if(editParams.status == 6){
                name = getLabel(19134, '审批中');
                title = getLabel(518619, '任务提交完成,待确认人审批')+(auditperson?"("+auditperson+")":"");
                _type = "";
            }else{
                name = getLabel(23774, '已完成');
                i_type = "icon-coms-Approval";
            }
            arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@fpubv5@commonkey`} title={title}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@2yvkg3@commonkey`} onClick={() => this.toChangeStatus(_type)} type={editParams.status == 2 ? "primary" : ""}>{name}</Button></Tooltip>);
            if(i_type!=""){
                rightarry.push({key: '4',icon: <i className={i_type} />,content: name,onClick: key => this.toChangeStatus(_type)});
            }
        }
        if (candel) {
            arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@rn66p0@deltask`} title={getLabel(382576, '删除任务')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@i14y4g@deltask`} onClick={() => this.toChangeStatus('del')}>{getLabel(91, '删除')}</Button></Tooltip>);
            rightarry.push({key: '5',icon: <i className='icon-coms-Delete' />,content: getLabel(91, '删除'),onClick: key => this.toChangeStatus('del')});
        }
        // if(canremind){
        //     arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@9210nq@urging`} title={getLabel(517825, '催办任务')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@6rggkv@urging`} onClick={() => this.refuseDialog(true,2,getLabel(517825, '催办任务'))}>{getLabel(23756, '催办')}</Button></Tooltip>);
        //     rightarry.push({key: '7',icon: <i className='icon-coms-daiban' />,content: getLabel(23756, '催办'),onClick: key => this.refuseDialog(true,2,getLabel(517825, '催办任务'))});
        // }
        if (canremind) {
            arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@9210nq@urging`} title={getLabel(517825, '催办任务')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@6rggkv@urging`} onClick={() => this.toChangeStatus("status",103,getLabel(517830,'确认要催办此任务吗？'))}>{getLabel(23756, '催办')}</Button></Tooltip>);
            rightarry.push({key: '7',icon: <i className='icon-coms-daiban' />,content: getLabel(23756, '催办'),onClick: key => this.toChangeStatus("status",103,getLabel(517830,'确认要催办此任务吗？'))});
        }
        if(canaudit){
            arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@ed4z5a@agreetask`} title={getLabel(515162, '同意此任务标记完成')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@k8r8b5@agreetask`} onClick={()=>this.toChangeStatus("status",104,getLabel(515165,'确认要同意任务标记完成？'))}>{getLabel(142, '批准')}</Button></Tooltip>);
            arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@r7nwur@refusetask`} title={getLabel(515163, '拒绝此任务标记完成')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@mid3xv@refusetask`} onClick={()=>this.toChangeStatus("status",105,getLabel(515166,'确认要拒绝任务标记完成？'))}>{getLabel(236, '退回')}</Button></Tooltip>);
        }
        arry.push(<Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@hyk6x2@feedback`} title={getLabel(382577, '反馈任务')}><Button ecId={`${this && this.props && this.props.ecId || ''}_Button@kt5qir@feedback`} onClick={() => this.startFb()}>{getLabel(21950, '反馈')}</Button></Tooltip>);
        rightarry.push({key: '6',icon: <i className='icon-coms-Need-feedback' />,content: getLabel(21950, '反馈'),onClick: key => this.startFb()});
        if(_btype==1){
            return rightarry;
        }else{
            return arry;
        }
    }
    //右上角 标记完成 关注 删除
    toChangeStatus(type,_v,_tv) {
        const { taskDetailStore } = this.props;
        const { detailKey, editParams } = taskDetailStore;
        let _this = this;
        if (type == 'status') {
            let status = 1;
            let statustitle = "";
            let _refuseval = "";//理由
            let haspval = 1;
            let hascval = 0;
            if(_v && _v!=""){
                if(_v==5){
                    const {refuseval} = this.state;
                    if(refuseval==""){
                        message.warning(getLabel(516927,'请填写拒绝理由'));
                        return;
                    }
                    _refuseval = refuseval;
                }
                if(_v==103){
                    const {remindval,pcheckval,ccheckval} = this.state;
                    if(pcheckval==0 && ccheckval==0){
                        message.warning(getLabel(32808,'请至少选择1个提醒对象'));
                        return;
                    }
                    _refuseval = remindval;
                    haspval = pcheckval;
                    hascval = ccheckval;
                }
                status = _v;
                statustitle = _tv;
            }else{
                statustitle = getLabel(508676, '确认要标记此任务为进行中吗？');
                if (editParams.status == 1) {
                    status = 2;
                    statustitle = getLabel(508674, '确认要标记此任务为完成吗？');
                }
            }
            Modal.confirm({
                title: getLabel(131329, '信息确认'),
                content: statustitle,
                onOk() {
                    taskDetailStore.toChangeStatus({
                        "taskId": detailKey, "status": status,refuseval:_refuseval,sendObject:haspval+","+hascval, doback: function (sList,_del,newstatus) {
                            message.success(getLabel('30700', '操作成功'), 2);
                            if( status == 1 ||  status ==2){
                                taskDetailStore.editParams.status = newstatus || status;
                                _this.doCallBack('changeStatus', toJS(sList));
                            }else if(status == 100){
                                _this.doCallBack('changeStatus', toJS(sList),'',1,_del);
                            }else if(status == 5){
                                _this.doCallBack('del');
                                _this.refuseDialog(false);
                            }else if(status == 103){
                                _this.refuseDialog(false);
                            }else if(status == 104 || status == 105){
                                _this.doCallBack('changeStatus', toJS(sList),'',status == 104?2:1);
                            }
                        }
                    });
                },
                onCancel() { },
            });
        } else if (type == 'collection') {
            taskDetailStore.setSpecial({
                taskid: detailKey, special: editParams.special, doback: function (sList) {
                    message.success(getLabel(31439, '更新成功!'), 2);
                    _this.doCallBack('changeStatus', sList);
                }
            });
        } else if (type == 'del') {
            Modal.confirm({
                title: getLabel(131329, '信息确认'),
                content: getLabel(508794, '确认要删除此任务吗？'),
                onOk() {
                    taskDetailStore.toChangeStatus({
                        "taskId": detailKey, "status": 4, doback: function () {
                            message.success(getLabel(83472, '删除成功!'), 2);
                            _this.doCallBack('del');
                        }
                    });
                },
                onCancel() { },
            });
        }else if(type=="resend"){ //重发任务
            Modal.confirm({
                title: getLabel(131329,'信息确认'),
                content: getLabel(515097,'确认要重新向责任人发送此任务吗？'),
                onOk() {
                    taskDetailStore.toChangeStatus({
                        "taskId": detailKey, "status": 102, doback: function (sList) {
                            message.success(getLabel(30700,'操作成功!'), 2);
                            _this.doCallBack('changeStatus',toJS(sList),'',4);
                        }
                    });
                },
                onCancel() { },
            });
        }
    }
    startFb() {//右上角反馈
        const { taskDetailStore } = this.props;
        taskDetailStore.isFb = 1;
        taskDetailStore.tabselectKey = 4;
    }
    //编辑修改内容回调taskMain.js
    doCallBack=(type, dataArray, key, cstatus,candelete)=> {
        if (typeof this.props.onEditSuccess === "function" || typeof this.props.onDialogSuccess === "function") {
            let optparams = {};
            const { taskDetailStore } = this.props;
            if (key && key.length > 0) {
                optparams.optkey = key;
            } else {
                optparams.optkey = taskDetailStore.detailKey;
            }
            if (type == "name") {//任务名称修改回调
                optparams.opttype = "update";
                optparams.title = taskDetailStore.editParams.name;
            } else if (type == "del") {
                optparams.opttype = 'del';
            } else if (type == 'changeStatus') {
                optparams.opttype = "update";
                if (cstatus && cstatus > 0) {
                    optparams.status = cstatus;
                } else {
                    optparams.status = taskDetailStore.editParams.status;
                }
                if(candelete){
                    optparams.candelete = candelete;
                }
                optparams.comsbtn = dataArray;
            } else if (type == 'updateperson') {
                optparams.opttype = type;
                optparams.personname = dataArray;
            } else if (type == "principalid" || type == "enddate" || type == "addfb") {//责任人  结束时间修改回调
                let optarray = [];
                let optclass = {};
                optclass.name = taskDetailStore.editParams.principalArray[0].name;//责任人名称
                optclass.classname = "hrmdiv";
                optarray.push(optclass);
                optclass = {};
                optclass.name = taskDetailStore.editParams.enddate;//结束时间
                optarray.push(optclass);
                if (taskDetailStore.feedbackcount > 0) {
                    optclass = {};
                    optclass.name = '(' + taskDetailStore.feedbackcount + ')';//返回数量
                    optarray.push(optclass);
                }
                optparams.status = taskDetailStore.editParams.status;
                optparams.opttype = "update";
                optparams.rightData = optarray;
            } else if (type == "addnew") {
                optparams = dataArray;
            } else if (type == "delsub") {//批量删除回调
                optparams.opttype = type;
                optparams.delData = dataArray;
            } else if (type == "tag") {//更新单个任务标签
                optparams.opttype = "update";
                optparams.tags = dataArray;
            } else if (type == "batchtag") {//批量更新任务标签
                optparams.opttype = type;
                optparams.optkeys = cstatus;
                optparams.tags = dataArray;
            }
            if (typeof this.props.onEditSuccess === "function") {
                this.props.onEditSuccess(optparams);
            } else if (typeof this.props.onDialogSuccess === "function") {
                this.props.onDialogSuccess(this.state.showKey, '1', optparams);
            }
        }
    }
    /** 添加下级任务 */
    addSubTask() {
        this.refs.subTaskRef.wrappedInstance.addSubTask(1);
    }
    hideSlide() {
        if (typeof this.props.onEditSuccess === "function") {
            this.props.onEditSuccess('', 1);
        }
    }
    changeData=(theKey)=> {
        const { taskDetailStore } = this.props;
        if (theKey == 1 || taskDetailStore.tabselectKey == 1) {
            this.resetUrlKey();
        }
        taskDetailStore.tabselectKey = theKey;
        if (theKey != 1) {
            taskDetailStore.spinning = true;
        }
    }

    onChoiceBoxBottomClick = (type, tagList) => {
        const { changeTagChoiceBoxVisible } = this.props.taskDetailStore
        if (type == "0") {     // 取消所有标记
            changeTagChoiceBoxVisible(false)
            Modal.confirm({
                title: getLabel('386786', '信息确认'),
                content: getLabel('517867','确认取消所有标记吗？'),
                onOk: () => {
                    this.updateTaskTagInfo([])
                }
            })
        } else if (type == "1") {       // 确定
            this.updateTaskTagInfo(tagList)
        }
    }

    onTaskRelatedTagItemDelete = (event, tag) => {
        event.preventDefault()
        event.stopPropagation()
        const { editParams } = this.props.taskDetailStore
        this.updateTaskTagInfo(editParams.tagArray.filter((d, i) => d.id != tag.id))
    }

    updateTaskTagInfo = (newTaskTagList = []) => {
        const { editParams, detailKey, editTaskInfo, changeTagChoiceBoxVisible } = this.props.taskDetailStore
        let newIdsStr = "," + newTaskTagList.sort((a, b) => parseInt(a.id) - parseInt(b.id)).map((d, i) => d.id + "").join(",") + ","
        let oldIdsStr = "," + editParams.tagArray.sort((a, b) => parseInt(a.id) - parseInt(b.id)).map((d, i) => d.id).join(",") + ","
        let delValue = Util.ArrayDiffer(oldIdsStr, newIdsStr, 1)
        let addValue = Util.ArrayDiffer(oldIdsStr, newIdsStr.split(","), 2)

        if (newIdsStr !== oldIdsStr) {
            let _this = this;
            editTaskInfo({
                taskId: detailKey,
                fieldname: "tag",
                fieldvalue: newIdsStr,
                fieldtype: "str",
                addvalue: addValue,
                delvalue: delValue,
                doback: (status, msg) => {
                    changeTagChoiceBoxVisible(false)
                    status == 1 && message.success(getLabel(31439, "更新成功"), 1)
                    _this.doCallBack('tag', editParams.tagArray);
                }
            })
        } else {
            changeTagChoiceBoxVisible(false)
        }
    }

    onTagSettingSureClick = (datas = []) => {
        const { editParams } = this.props.taskDetailStore
        let newTagArray = []
        editParams.tagArray.forEach((et, ei) => {
            datas.forEach((dt, di) => {
                if (et.id == dt.id) {
                    et.name = dt.name
                    et.color = dt.color
                }
            })
        })
    }

    getTabButtons(ecId){
        const {dropData} = this.state;
        const {dropdisplay,dropSelectedKey,tabselectKey,cancreate} = this.props.taskDetailStore;
        if(cancreate && tabselectKey == 2){
            return [(<Button ecId={`${ecId}_Button@3v5o7r@newsubtask`} type="primary" onClick={() => this.addSubTask()}>{getLabel(83924, '新建子任务')}</Button>),
            (<ButtonSelect ecId={`${ecId}_ButtonSelect@zurgun@subbatchbtn`} datas={dropData} btnProps={{disabled:dropdisplay}} selectedKey={dropSelectedKey} btnOnClick={(key) => this.btnOnClick(key)} menuOnClick={(key)=>this.menuOnClick(key)}/>)];
        }else{
            return [];
        }
    }
    menuOnClick(key){
        const {taskDetailStore} = this.props;
        taskDetailStore.dropSelectedKey = key;
    }
    btnOnClick(key){
        const { taskDetailStore } = this.props;
        if(key==1){
            let _sublist = taskDetailStore.editParams.sublist;
            let taskIds = Util.getDataListIds(_sublist,true,4);
            if(taskIds==""){
                message.warning(getLabel(501159, '请选择要操作的数据'));
                return;
            }
            let _this = this;
            Modal.confirm({
                title: getLabel(131329, '信息确认'),
                content: getLabel(513503, '确认要删除选中记录吗？'),
                onOk() {
                    taskDetailStore.batchDelTask({
                        taskIds: taskIds, doback: function (status) {
                            message.success(getLabel(83472, '删除成功!'), 2);
                            if (status == 1) {
                                _this.doCallBack('delsub', Util.operateSymbol(taskIds, ',', 'del').split(","));
                            }
                        }
                    });
                },
                onCancel() { },
            });
        }else {
            taskDetailStore.checkedIds = "";
            taskDetailStore.changeSubTagBoxVisible(true, 1);
        }
    }
    checkList = (type, checklist) => {
        const { taskDetailStore, taskDetailStore: { changeSubTagBoxVisible, opentagtype, selecttaskid, editParams } } = this.props;
        let taskids = "";
        if (opentagtype == 1) {
            taskids = Util.getDataListIds(editParams.sublist, false, 4);
        } else {
            taskids = selecttaskid;
        }
        if (taskids == "") {
            message.warning(getLabel(501159, '请选择要操作的数据'));
            return;
        }
        changeSubTagBoxVisible(false, 1);
        let _this = this;
        if (type == "0") {     // 取消所有标记
            let _title = opentagtype == 1 ? getLabel(516448, "确定要清除选中数据的所有标签吗？") : getLabel('516445', '确认清除所有标签吗？');
            Modal.confirm({
                title: getLabel('386786', '信息确认'),
                content: _title,
                onOk: () => {
                    taskDetailStore.editTaskInfo({
                        fieldname: "tag", taskids: taskids, tagtype: "3", doback: function (status) {
                            if (status == 1) {
                                _this.doCallBack('batchtag', [], "1", Util.operateSymbol(taskids, ',', 'del').split(","));
                            }
                        }
                    });
                }
            })
        } else if (type == "1") {       // 确定
            let newIdsStr = checklist.map((d, i) => d.id).join(",");
            taskDetailStore.editTaskInfo({
                addvalue: newIdsStr, fieldname: "tag", taskids: taskids, tagtype: "2", opentagtype: opentagtype, doback: function (status, msg, taskTagMap) {
                    if (status == 1) {
                        _this.doCallBack('batchtag', taskTagMap, "2", Util.operateSymbol(taskids, ',', 'del').split(","));
                    }
                }
            });
        }
    }
    onTextChange(value, type){
        this.setState({[type]:value});
    }
    refuseDialog(v,type,_title){
        if(v){
            if(v==2){
                this.setState({remindval:getLabel(517830, '请抓紧处理此任务'),pcheckval:1,ccheckval:0});
            }
            this.setState({refusevisable:v,currentbtn:type,dialogtitle:_title});
        }else{
            this.setState({refusevisable:v});
        }
    }
    dialogSure(){
        const {currentbtn} = this.state;
        if(currentbtn==1){
            this.toChangeStatus("status",5,getLabel(515084,'确认要拒绝此任务吗？'));
        }
        if(currentbtn==2){
            this.toChangeStatus("status",103,getLabel(517830,'确认要催办此任务吗？'));
        }
    }
    onTaskCoumnChange(v,type,optype){
        const {taskDetailStore,taskDetailStore:{editParams,detailKey}} = this.props;
        if(optype==1){
            if (editParams[type] != v) {
                taskDetailStore.editParams[type] = v;
            }
        }else{
            taskDetailStore.editParams[type] = v;
            taskDetailStore.canEdit = false;
            let _this = this;
            taskDetailStore.editTaskInfo({taskId: detailKey, fieldname: type, fieldvalue: v,fieldtype:"str",doback:function(status){
                if(status==1){
                    message.success(getLabel(31439, '更新成功!'), 2);
                    _this.doCallBack()
                }
            }});
        }
    }
    render() {
        let { viewHeight, topTab,refusevisable,refuseval,collectParams,currentbtn,dialogtitle,remindval,pcheckval,ccheckval} = this.state;
        const { taskDetailStore, isshow, sorttype, isopen } = this.props;
        const { spinning, hasData, errormsg, editParams, tabselectKey, tagChoiceBoxVisible, subtagvisible, changeSubTagBoxVisible,
            changeTagChoiceBoxVisible, taskitemTaglistPopoverVisible, changeTaskitemTaglistPopoverVisible, checkedIds,newfbcount,canEdit} = taskDetailStore;
        return (
            <div className="wea-workrelate-task-taskedit wea-workrelate-common-top">
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@t2tu6v`} datas={this.getButtons(1)} collectParams={collectParams}>
                <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@u31diw`} spinning={spinning}>
                    <WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@ak6xzi`} />
                    {!isshow && <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@glym1z`}
                        title={
                            <span className="wea-workrelate-taskedit-title-wrapper">
                                <span className="wea-workrelate-taskedit-title">
                                    <span className="wea-workrelate-taskedit-title-text" title={editParams.name ? getLabel(1352, '任务名称') + ":" + editParams.name : getLabel(508789, '任务详情')}>
                                        {hasData && editParams.name ? editParams.name : getLabel(508789, '任务详情')}
                                    </span>
                                    {hasData && <span>
                                        <span className="wea-workrelate-taskedit-title-icons-wrapper">
                                            <span className="wea-workrelate-taskedit-title-icon-wrapper">
                                                <Popover ecId={`${this && this.props && this.props.ecId || ''}_Popover@3fxo1m`} trigger="hover" overlayClassName={"taskedit-taskprogress-popover"}
                                                    placement={"bottomLeft"}
                                                    title={getLabel(517158,"任务进度")}
                                                    content={
                                                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@qp15c1`}>
                                                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@bu42mn`} span={22}><Slider ecId={`${this && this.props && this.props.ecId || ''}_Slider@6gok80`} min={0} max={100} step={10} tipFormatter={(v)=>{return `${v}%`}} disabled={editParams.status==4?true:!canEdit} value={editParams.taskprogress}
                                                                 onChange={(v)=>this.onTaskCoumnChange(v,"taskprogress",1)} onAfterChange={(v)=>this.onTaskCoumnChange(v,"taskprogress")}/></Col>
                                                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@vsdhsh`} span={2}><span className="taskedit-taskprogress-span">{editParams.taskprogress+"%"}</span></Col>
                                                        </Row>
                                                    }>
                                                    <div className="taskedit-progress" style={editParams.taskprogress==100?{color:"#68D358"}:{}}>{editParams.taskprogress+"%"}
                                                       <div className="taskedit-progress-title"><WeaProgress ecId={`${this && this.props && this.props.ecId || ''}_WeaProgress@t78oyi`} percent={editParams.taskprogress} showInfo={false} strokeColor={editParams.taskprogress==100?"#68D358":"#2DB7F5"}/></div>
                                                    </div>
                                                </Popover>
                                            </span>
                                            <span className="wea-workrelate-taskedit-title-icon-wrapper">
                                                <TagChoiceBox ecId={`${this && this.props && this.props.ecId || ''}_TagChoiceBox@r4xa9f`}
                                                    isDialog={false}
                                                    visible={tagChoiceBoxVisible}
                                                    checkedIds={editParams.tagArray.map((d, i) => d.id + "")}
                                                    onCallBack={this.onChoiceBoxBottomClick}
                                                    onDialogClose={() => {
                                                        changeTagChoiceBoxVisible(false)
                                                    }}
                                                    onSettingSureClick={this.onTagSettingSureClick}
                                                    classStyle="taskedit-tag-topdiv"
                                                />
                                            </span>
                                        </span>
                                        <span className="wea-workrelate-taskedit-title-tags-wrapper">
                                            <span className="wea-workrelate-taskedit-title-tags-wrapper-abs">
                                                {
                                                    editParams.tagArray.map((tag, ti) => {
                                                        const tagShowCount = 3     // 最多只显示3个标签
                                                        if (ti < tagShowCount) {
                                                            return (
                                                                <span title={formatMultiLang(tag.name)}>
                                                                    <WeaTag ecId={`${this && this.props && this.props.ecId || ''}_WeaTag@fang09@${tag.id}`}
                                                                        key={tag.id}
                                                                        id={tag.id}
                                                                        closable={true}
                                                                        onClose={(e) => this.onTaskRelatedTagItemDelete(e, { ...tag })}
                                                                        color={tag.color}>
                                                                        {formatMultiLang(tag.name)}
                                                                    </WeaTag>
                                                                </span>
                                                            )
                                                        } else if (ti === tagShowCount) {
                                                            return (
                                                                <Popover ecId={`${this && this.props && this.props.ecId || ''}_Popover@l8eoqj@taglist`}
                                                                    // visible={true}
                                                                    trigger="hover"
                                                                    overlayClassName={"wea-workrelate-taskedit-taskitem-taglist-popover-wrapper"}
                                                                    placement={"bottomRight"}
                                                                    onVisibleChange={(visible) => changeTaskitemTaglistPopoverVisible(visible)}
                                                                    content={
                                                                        <div>
                                                                            {
                                                                                editParams.tagArray.map((tag2, ti2) => {
                                                                                    return (
                                                                                        <div title={formatMultiLang(tag2.name)} className="wea-workrelate-taskedit-taskitem-taglist-popover-item">
                                                                                            <WeaTag ecId={`${this && this.props && this.props.ecId || ''}_WeaTag@w8n8t4@${tag2.id}`}
                                                                                                key={tag2.id}
                                                                                                id={tag2.id}
                                                                                                closable={true}
                                                                                                onClose={(e) => this.onTaskRelatedTagItemDelete(e, { ...tag2 })}
                                                                                                color={tag2.color}
                                                                                            >
                                                                                                {formatMultiLang(tag2.name)}
                                                                                            </WeaTag>
                                                                                        </div>
                                                                                    )
                                                                                })
                                                                            }
                                                                        </div>
                                                                    }
                                                                >
                                                                    <i className={taskitemTaglistPopoverVisible ? "icon-coms-down" : "icon-coms-right"} style={{ marginLeft: 5 }} />
                                                                </Popover>
                                                            )
                                                        }
                                                    })
                                                }
                                            </span>
                                        </span></span>}
                                </span>
                                {
                                    hasData &&
                                    <span className="wea-workrelate-task-createinfo-wrapper">
                                        <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@5olgqy`} title={`${getLabel(882, '创建人')}:${editParams.creatername + "  " + getLabel(1339, '创建时间')}:${editParams.createdate}`}>
                                            <span className="wea-workrelate-task-createinfo" dangerouslySetInnerHTML={{ __html: editParams.creater + editParams.createdate }}></span>
                                        </Tooltip>
                                    </span>
                                }
                            </span>
                        }
                        icon={!isopen ? <i className="icon-coms-implement" /> : <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@3cr9vo`} title={getLabel(508788, '关闭侧边框')}><i className='icon-coms-Right icursor-pointer' onClick={() => this.hideSlide()} /></Tooltip>}
                        iconBgcolor={!isopen ? "rgb(150, 53, 138)" : ""}
                        buttons={this.getButtons()}
                    />}
                    {errormsg != "" ? Util.renderAlertPage(errormsg,'','','',this.props.ecId || '') :
                        hasData &&
                        <div><WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@3bionr`}
                            datas={topTab}
                            counts={newfbcount}
                            keyParam="viewcondition"  //主键
                            countParam="groupid" //数量
                            onChange={this.changeData}
                            selectedKey={tabselectKey}
                            buttons={this.getTabButtons(this.props.ecId || '')}
                        />
                            <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@cptye8`} height={viewHeight} style={{ padding: '0px 10px' }} ref="taskNewScroll">
                                <div className="wea-workrelate-taskedit-content">
                                    {tabselectKey == 1 && <BaseInfo ecId={`${this && this.props && this.props.ecId || ''}_BaseInfo@tdh889`} doCallBack={this.doCallBack} />}
                                    {tabselectKey == 2 && <SubTask ecId={`${this && this.props && this.props.ecId || ''}_SubTask@v9nivo`} ref="subTaskRef" sorttype={sorttype} doCallBack={this.doCallBack} />}
                                    {tabselectKey == 3 && <RelateInfo ecId={`${this && this.props && this.props.ecId || ''}_RelateInfo@ufykfl`} />}
                                    {tabselectKey == 4 && <FeedInfo ecId={`${this && this.props && this.props.ecId || ''}_FeedInfo@2tx03k`} doCallBack={this.doCallBack} />}
                                    {tabselectKey == 5 && <LogInfo ecId={`${this && this.props && this.props.ecId || ''}_LogInfo@uxof7y`} />}
                                </div>
                                {subtagvisible && <TagChoiceBox ecId={`${this && this.props && this.props.ecId || ''}_TagChoiceBox@iybe0a`} visible={subtagvisible} checkedIds={checkedIds} onDialogClose={() => changeSubTagBoxVisible(false, 1)} onCallBack={(key, checklist) => this.checkList(key, checklist)} />}
                            </WeaNewScroll>
                            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@932jr9`} visible={refusevisable} title={dialogtitle} icon="icon-coms-implement" iconBgcolor="rgb(150, 53, 138)"
                                buttons={[
                                    (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@zsmkgx@sure`} type="primary" onClick={()=>this.dialogSure()}>{getLabel(826, '确定')}</Button>),
                                    (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@ceq3vf@cancel`} type="ghost" onClick={()=>this.refuseDialog(false)}>{getLabel(31129, '取消')}</Button>)
                                ]}
                                style={{ width: window.innerWidth * 0.5, height: window.innerHeight*0.4}} closable={true}
                                onCancel={()=>this.refuseDialog(false)}>
                                 <div style={{margin:"15px"}}>
                                    {currentbtn==1 && <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@ebscy1`} value={refuseval} viewAttr="3" onChange={value => this.onTextChange(value, "refuseval")} placeholder={getLabel(516927, '请填写拒绝理由')}/>}
                                    {currentbtn==2 && <div>
                                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@8c9fk8`} value={remindval} viewAttr="2" onChange={value => this.onTextChange(value, "remindval")}/>
                                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@wgsbu0`} style={{marginTop:10}}>
                                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@cw98i5`} span={4}>{getLabel(18013, '提醒对象')}:</Col>
                                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@8ssjnw`} span={20}><WeaCheckbox ecId={`${this && this.props && this.props.ecId || ''}_WeaCheckbox@cnmk3y`} content={getLabel(84043, '责任人')} value={pcheckval} onChange={(v)=>this.onTextChange(v, "pcheckval")}/>
                                                           <WeaCheckbox ecId={`${this && this.props && this.props.ecId || ''}_WeaCheckbox@4bu777`} content={getLabel(382557, '参与人')} value={ccheckval} onChange={(v)=>this.onTextChange(v, "ccheckval")}/>
                                            </Col>
                                        </Row>
                                    </div>}
                                 </div>
                            </WeaDialog>
                        </div>}
                </Spin>
                </WeaRightMenu>
            </div >
        )
    }
};